package net.ruixin.session;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 登录控制器
 *
 * @author mxding
 * @date 2021-04-23 15:34
 */
@Controller
public class LoginController {

    /**
     * 登录页面
     */
    @RequestMapping("/login")
    public String login() { return "login.html"; }

    /**
     * 权限认证URL
     */
    @RequestMapping({"/", "/index"})
    public String index() {
        return "index.html";
    }

    /**
     * 登录验证
     * @param username 用户名
     * @param password 密码
     */
    @RequestMapping("/loginValid")
    public String loginValid(String username, String password) {
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username, password);
        subject.login(token);
        return "redirect:index.html";
    }

}
